//新窗口打开
$("#newWindow").click((e) => {
  window.open(chrome.extension.getURL("main.html"));
});
//打开后台页
$("#openback").click((e) => {
  window.open(chrome.extension.getURL("back.html"));
});
//取后台页标题
$("#getbacktitle").click((e) => {
  var bg = chrome.extension.getBackgroundPage(); //后台页对象
  // console.log(bg);
  alert(bg.document.title);
});
//设置后台页标题
$("#setbacktitle").click((e) => {
  var title = prompt("新标题", "标题");
  var bg = chrome.extension.getBackgroundPage();
  bg.document.title = title;
});
//调用后台脚本
$("#callback_js").click((e) => {
  var bg = chrome.extension.getBackgroundPage(); //后台页对象
  bg.backjs();
});
//badge状态开
$("#show_badge").click((e) => {
  chrome.browserAction.setBadgeText({ text: "状态" });
  chrome.browserAction.setBadgeBackgroundColor({ color: [0, 0, 255, 80] });
});
//badge状态管
$("#hide_badge").click((e) => {
  chrome.browserAction.setBadgeText({ text: "" });
  chrome.browserAction.setBadgeBackgroundColor({ color: [0, 0, 0, 0] });
});
//插件发送通知
$("#pop_notify").click((e) => {
  chrome.notifications.create(null, {
    type: "image",
    iconUrl: "image/icon.png",
    title: "通知",
    message: "这是demo弹出的信息",
    imageUrl: "image/ts.png",
  });
});
//插件修改样式
$("#update_css").click((e) => {
  var bg = chrome.extension.getBackgroundPage(); //后台页对象
  bg.getTabId((id) => {
    chrome.tabs.executeScript(id, {
      code: `document.body.style.backgroundColor = "red"`,
    });
  });
});

{
  //点击插件时调用
  // $("#show_badge").click();
}

//http://chrome.cenchy.com/
